package gamesys;

import java.awt.Color;
import java.awt.Graphics2D;
import pkg.*;

@SuppressWarnings("serial")
public class BaseGame extends GamePanel {

	protected ComponentCollection components;
	protected FpsCounter counter;
	protected EntityManager manager;
	private int targetFps = 60;
	
	public BaseGame(){
		components = new ComponentCollection();
		
	}

	protected void intitialize(){
		setupBasics();
	}
	protected void setupBasics(){
		
		counter = new FpsCounter();
		manager = new EntityManager();
		components.addComponent(manager);
		components.addComponent(counter);
	}
	
	protected void render(Graphics2D g) {
	
		float dt = 1;
		if(counter.getCurrentFps() != 0)
			dt = targetFps/(float)counter.getCurrentFps();
		components.update(dt);
		
		g.setColor(Color.BLACK);
		g.fillRect(0, 0, getWidth(), getHeight());
		
		
		components.render(g);
		

	}
	
	public void setTargetFps(int target)
	{
		targetFps = target;
	}
}
